﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RangeValidator2.MaximumValue = DateTime.Now.ToString("yyyy-MM-dd");
        }

        protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {
            if (args.Value == "admin")
            {
                args.IsValid = false;
            }
            else {
                args.IsValid = true;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Page.IsValid) {
                Literal2.Text = "注册成功 <a href='/WebForm2.aspx'>点击跳转</a>";
            }
            if (Ful.HasFile == true)
            {
                string path = Ful.FileName;
                if (path.EndsWith(".jpg") || path.EndsWith(".jpeg") || path.EndsWith(".png") || path.EndsWith(".gif"))
                {
                    string url = Server.MapPath(@"~\image\" + path);
                    Ful.SaveAs(url);
                    Image1.ImageUrl = @"~\img\" + path;
                }
                else
                {
                    this.ClientScript.RegisterClientScriptBlock(GetType(), "提示", "<script>alert('文件格式不正确！')</script>");
                    return;
                }

            }
            else {
                Literal1.Text = "<script>alert('文件格式不正确!')</script>";
                return;
            }
        }
    }
}